package com.woniuxy.util;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.InvocationHandler;

import java.lang.reflect.Method;

/**
 * @ClassName CgLibProxyInstance
 * @Description TODO
 * @Author LI.hh
 * @Date 2022/8/22 19:15
 * @Version 1.0
 */
public class CgLibProxyInstance {
    public Object getSon(Object object){
        return Enhancer.create(object.getClass(), new InvocationHandler() {
            @Override
            public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
                System.out.println("进入了"+method.getName()+"方法");
                Object invoke= method.invoke(object, objects);
                System.out.println("退出了"+method.getName()+"方法");
                return invoke;
            }
        });
    }
}
